package com.hxy.example.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.hxy.example.R;
import com.hxy.example.base.BaseRecyclerAdapter;
import com.hxy.example.base.BaseViewHolder;
import com.hxy.example.layoutmanager.CustomLayoutManager;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements BaseRecyclerAdapter.ItemClick,BaseRecyclerAdapter.ItemLongClick{
    private RecyclerView rv;
    private BaseRecyclerAdapter mAdapter;
    private ArrayList<String> data = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
        initAdapter();


    }

    private void initView(){
        rv = findViewById(R.id.mRecyclerView);
    }

    private void initData(){
        for (int i = 0; i < 100; i++){
            data.add("第"+(i+1)+"条");
        }
    }

    private void initAdapter(){
        mAdapter = new BaseRecyclerAdapter<String>(this,R.layout.rv_list_item,data) {

            @Override
            public void convert(final BaseViewHolder holder, String integer) {
                holder.setText(R.id.btn_one,integer);
//                holder.getView(R.id.btn_one).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Toast.makeText(MainActivity.this, "点击了第"+(holder.getAdapterPosition()+1)+"个", Toast.LENGTH_SHORT).show();
//                    }
//                });
            }
        };

        CustomLayoutManager layoutManager = new CustomLayoutManager(this);
        rv.setLayoutManager(layoutManager);
        rv.setAdapter(mAdapter);
        mAdapter.setItemClick(this);
        mAdapter.setItemLongClick(this);
    }

    @Override
    public void setOnClick(int index) {
        Toast.makeText(this, "点击了item："+index, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void setOnLongClick(int index) {

    }
}